package com.usian.controller;

import com.usian.feign.ItemServiceFrign;
import com.usian.pojo.TbItemParam;
import com.usian.utils.PageResult;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/backend/itemParam")
public class ItemParamController {

    @Autowired
    private ItemServiceFrign itemServiceInterface;

    /**
     * 规格模板查询
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("/selectItemParamAll")
    public Result selectItemParamAll(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "20")Integer rows){
        PageResult pageResult = itemServiceInterface.selectItemParamAll(page,rows);
        if (pageResult.getResult().size()>0){
            return Result.ok(pageResult);
        }
        return Result.error("查无结果");
    }

    /**
     * 查询商品规格参数模板
     * @param itemCatId
     * @return
     */
    @RequestMapping("/selectItemParamByItemCatId/{itemCatId}")
    public Result selectItemParamByItemCatId(@PathVariable Long itemCatId){
        TbItemParam tbItemParam = itemServiceInterface.selectItemParamByItemCatId(itemCatId);
        if (tbItemParam!=null){
            return Result.ok(tbItemParam);
        }
        return Result.error("查无结果");
    }

    /**
     * 商品规格模板添加
     * @param itemCatId
     * @param paramData
     * @return
     */
    @RequestMapping("/insertItemParam")
    public Result insertItemParam(@RequestParam Long itemCatId,@RequestParam String paramData){
        Integer num = itemServiceInterface.insertItemParam(itemCatId,paramData);
        if (num>0){
            return Result.ok("ok");
        }
        return Result.error("添加失败");
    }

    /**
     * 商品规格模板删除
     * @param id
     * @return
     */
    @RequestMapping("deleteItemParamById")
    public Result deleteItemParamById(@RequestParam Long id){
        Integer num = itemServiceInterface.deleteItemParamById(id);
        if (num>0){
            return Result.ok("ok");
        }
        return Result.error("删除失败");
    }
}
